package cxydmmszl.chapter08.t132;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * <li style="color: red;">Prob</li>
 * 在数组中找到一个局部最小的位置
 * <li style="color: red;">Desc</li>
 *
 * <li style="color: red;">Link</li> CD28
 *
 * @author habitplus
 * @since 2021-09-06 11:22
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(bf.readLine());
        int[] arr = new int[n];
        String[] ss = bf.readLine().split(" ");

        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(ss[i]);
        }

        int ans = getLessIndex(arr);
        System.out.println(ans);
    }

    public static int getLessIndex(int[] arr) {
        if (arr == null || arr.length == 0) {
            return -1;
        }
        int n = arr.length;
        if (n == 1 || arr[0] < arr[1]) {
            return 0;
        }

        if (arr[n - 1] < arr[n - 2]) {
            return n - 1;
        }

        int l = 1, r = n - 2, m;

        while (l < r) {
            m = (l + r) / 2;
            if (arr[m] > arr[m - 1]) {
                r = m - 1;
            } else if (arr[m] > arr[m + 1]) {
                l = m + 1;
            } else {
                return m;
            }
        }

        return l;
    }
}
